<?php

defined('_SECURITY_TOKEN') or die("caia fora");

class access_statistics
{
	
	function __construct(  )
	{
		
		
		
	}
	
	
	public function set_access_statistics_api( $parameters ){
				

		try {
			
				
			$db = application::getDb( configuration::db_type);
	// 		
			$db->setParameters(configuration::db_server, 
								configuration::db_port, 
								configuration::db_username, 
								configuration::db_password,
								configuration::db_name);
	
			$query = sprintf("INSERT INTO \"%s%s\" (
										component, 
										  controller,
										  task,
										  from_address, 
										  parameters,
										  user_id,
										  method)
							VALUES
										('%s',
										'%s',
										'%s',
										'%s',
										'%s',
										 %u,
										'%s')",
								configuration::table_prefix,		
			                 	configuration::table_access_statistics_api, 
			                 	$parameters->component,
			                 	$parameters->controller,
			                 	$parameters->task,
			                 	$_SERVER['REMOTE_ADDR'],
			                 	json_encode($parameters),
			                 	application::getUser_id(),
								$_SERVER['REQUEST_METHOD']);
				
				//try{
			$result = $db->setQuery($query);
					
				//}catch (AppException $e) {
			    	//$result=false;
			    //}
		
	
		 }
	    catch (AppException $e) {
	    	throw new AppException( $e->getMessage() );
	    }
	
	
	}

	

	public function set_access_statistics_download( $parameters ){
				

		try {
			
				
			$db = application::getDb( configuration::db_type);
	// 		
			$db->setParameters(configuration::db_server, 
								configuration::db_port, 
								configuration::db_username, 
								configuration::db_password,
								configuration::db_name);
	
			$query = sprintf("INSERT INTO \"%s%s\" (
										key_data, 
										from_address,
										notation,
										metadata,
										user_id)
							VALUES
										('%s',
										'%s',
										'%s',
										'%s',
										 %u)",
								configuration::table_prefix,		
			                 	configuration::table_access_statistics_download, 
			                 	$parameters->key,
			                 	$_SERVER['REMOTE_ADDR'],
			                 	$parameters->notation,
			                 	$parameters->metadata,
			                 	application::getUser_id());
				
				//try{
			$result = $db->setQuery($query);
					
				//}catch (AppException $e) {
			    	//$result=false;
			    //}
		
	
		 }
	    catch (AppException $e) {
	    	throw new AppException( $e->getMessage() );
	    }
	
	
	}
	
	
}